# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

#================================================================
# libcashew
#
# libcashew contains the bulk of the cashew source code
# we link it with main.cc to produce cashewd, and we link it with
# our *_unittest.cc sources to produce our unit test executable
#================================================================

noinst_LTLIBRARIES = libcashew.la

libcashew_la_SOURCES = \
  aggregator.h \
  aggregator.cc \
  aggregator_impl.h \
  aggregator_impl.cc \
  byte_counter.h \
  byte_counter.cc \
  cashew_server.h \
  cashew_server.cc \
  data_plan.h \
  data_plan.cc \
  data_plan_provider.h \
  data_plan_provider.cc \
  date.h \
  date.cc \
  default_policy.h \
  default_policy.cc \
  device.h \
  device.cc \
  device_impl.h \
  device_impl.cc \
  http_fetcher.h \
  ipconfig.h \
  ipconfig.cc \
  ipconfig_impl.h \
  ipconfig_impl.cc \
  libcurl_http_fetcher.h \
  libcurl_http_fetcher.cc \
  metrics_manager.h \
  metrics_manager.cc \
  metrics_manager_impl.h \
  metrics_manager_impl.cc \
  policy.h \
  policy.cc \
  procfs_byte_counter.h \
  procfs_byte_counter.cc \
  property_changed_handler.h \
  property_changed_handler.cc \
  service.h \
  service.cc \
  service_impl.h \
  service_impl.cc \
  service_manager.h \
  service_manager.cc \
  service_manager_impl.h \
  service_manager_impl.cc

# D-Bus server stub generation
DBUSXX_XML2CPP = dbusxx-xml2cpp
cashew_server_glue.h: $(top_srcdir)/introspection/cashew.xml
	$(DBUSXX_XML2CPP) $^ --adaptor=$@

# D-Bus client stub generation
flimflam_device_client_glue.h: $(top_srcdir)/extrospection/flimflam-device.xml
	$(DBUSXX_XML2CPP) $^ --proxy=$@
flimflam_ipconfig_client_glue.h: $(top_srcdir)/extrospection/flimflam-ipconfig.xml
	$(DBUSXX_XML2CPP) $^ --proxy=$@
flimflam_manager_client_glue.h: $(top_srcdir)/extrospection/flimflam-manager.xml
	$(DBUSXX_XML2CPP) $^ --proxy=$@
flimflam_service_client_glue.h: $(top_srcdir)/extrospection/flimflam-service.xml
	$(DBUSXX_XML2CPP) $^ --proxy=$@

BUILT_SOURCES = \
  cashew_server_glue.h \
  flimflam_device_client_glue.h \
  flimflam_ipconfig_client_glue.h \
  flimflam_manager_client_glue.h \
  flimflam_service_client_glue.h

CLEANFILES = $(BUILT_SOURCES)

# most CFLAGS and LIBS info comes from PKG_CHECK_MODULES checks in configure.ac
# we manually define info below for libs with no pkg-config file

GFLAGS_CFLAGS =
GFLAGS_LIBS = -lgflags

METRICS_CFLAGS =
METRICS_LIBS = -lmetrics

# these COMMON defs are shared among libcashew, cashewd, and cashew_unittest

COMMON_CFLAGS = \
  -Wall -Werror \
  -I$(top_srcdir)/src \
  @BASE_CFLAGS@ \
  @CURL_CFLAGS@ \
  @DBUS_CPP_CFLAGS@ \
  $(GFLAGS_CFLAGS) \
  @GLIB_CFLAGS@ \
  @GLOG_CFLAGS@ \
  $(METRICS_CFLAGS)

COMMON_LIBS = \
  @BASE_LIBS@ \
  @CURL_LIBS@ \
  @DBUS_CPP_LIBS@ \
  $(GFLAGS_LIBS) \
  @GLIB_LIBS@ \
  @GLOG_LIBS@ \
  $(METRICS_LIBS)

libcashew_la_CXXFLAGS = \
  $(COMMON_CFLAGS)

libcashew_la_LIBADD = \
  $(COMMON_LIBS)

LIBCASHEW = ./libcashew.la

#==============
# cashew daemon
#==============

sbin_PROGRAMS = cashewd

cashewd_SOURCES = \
  main.cc

cashewd_CXXFLAGS = \
  $(COMMON_CFLAGS)

cashewd_LDADD = \
  $(LIBCASHEW) \
  $(COMMON_LIBS)

#===========
# unit tests
#===========

check_PROGRAMS = cashew_unittest

cashew_unittest_SOURCES = \
  aggregator_unittest.cc \
  cashew_unittest.cc \
  data_plan_unittest.cc \
  date_unittest.cc \
  default_policy_unittest.cc \
  device_mock.h \
  procfs_byte_counter_unittest.cc \
  service_manager_mock.h \
  service_mock.h

GMOCK_CFLAGS =
GMOCK_LIBS = -lgmock

GTEST_CFLAGS =
GTEST_LIBS = -lgtest

cashew_unittest_CXXFLAGS = \
  $(COMMON_CFLAGS) \
  $(GMOCK_CFLAGS) \
  $(GTEST_CFLAGS)

cashew_unittest_LDADD = \
  $(LIBCASHEW) \
  $(COMMON_LIBS) \
  $(GMOCK_LIBS) \
  $(GTEST_LIBS)
